package c.main.core;

import c.main.util.WebUtils;
import sun.plugin2.message.GetAppletMessage;

import javax.sql.DataSource;

/**
 * 单例类
 * Author: chengwei
 * Date:   2016/3/15
 * Time:   14:04
 */
public class C {
    
    private static C c = new C();
    private WcsContext context;
    public static C getInstance() {
        return c;
    }

    public WcsContext getContext() {
        return c.context;
    }

    public static void setContext(WcsContext context) {
        c.context = context;
    }

    public static  <T> T getBean(Class<T> clazz) {
        return c.context.getBean(clazz);
    }
    
    public static Object getBean(String key) {
        return c.context.getBeanMap().get(key);
    }
    
    public static void addBean(Object o) {
        c.context.addBean(o);
    }

    public static void addBean(String key,Object o) {
        c.context.addBean(key,o);
    }
    
    public static DataSource getDataSource(String s) {
        return c.context.getDataSourceMap(s);
    }

    public static DataSource getDataSource() {
        return getDataSource(WebUtils.DEFAULT_DATA_SOURCE);
    }
    
    public static void setDataSource (String s,DataSource dataSource) {
        c.context.setDataSource(s,dataSource);
    }
}
